<template>
	<uni-fav :checked="favorite.id>0" :content-text="contentText" bgColorChecked="#dd524d" circle @click="favClick()" />
</template>

<script>
	export default {
		name:"favorite",
		props:{
			// 院校UNI、专业SPECIAL、职业OCCUPATION
			type: {
				type: String,
				require: true
			},
			bizId: {
				type: Number,
				require: true
			}
		},
		data() {
			return {
				favorite: {},
				contentText: {
					contentDefault: '关注',
					contentFav: '已关注'
				}
			};
		},
		created() {
			if(this.$isLogin()){
				this.loadDate()
			}
		},
		methods:{
			// 获取是否已经收藏
			loadDate(){
				this.$get(this.$api.ucenter.favorite.exist,{type:this.type,bizId:this.bizId}).then(res => {
					if(res.data){
						this.favorite = res.data
					}
					console.log(res);
				})
			},
			favClick(){
				if(this.$isLogin(true)){
					if(this.favorite.id){
						// 取消收藏
						this.$post(this.$api.ucenter.favorite.delete+ this.favorite.id).then(res => {
							if(res.code === 200){
								this.favorite = {}
							}
							console.log(res);
						})
					}else{
						// 加入收藏
						this.$post(this.$api.ucenter.favorite.add,{type:this.type,bizId:this.bizId}).then(res => {
							if(res.code === 200){
								this.favorite = res.data
							}
							console.log(res);
						})
					}
				}
				
				console.log('favClick');
			}
		}
	}
</script>

<style>
</style>